<?php

class Personal_CartController extends Zend_Controller_Action
{
    private $_uid;
    public $_cart;
    public $_cbooks;
    public function init()
    {
        $this->_uid = 1;
        $this->_cart = new Personal_Model_MCart($this->_uid);

        $category=new Admin_Model_MCategory();
        $bookCategory=$category->getAllCategories(array("_id","name"));
        $this->view->category=$bookCategory;

        $mySession=new Zend_Session_Namespace();
        if(isset ($mySession->uid) && isset($mySession->username))
        {
            $this->view->username=$mySession->username;
            $this->view->uid=$mySession->uid;
        }
    }

    public function indexAction()
    {
        $this->_helper->layout()->setLayout('layout_personal');
        $this->view->user_name = 'Xin chao, Taint';

        $upagesize = 3;
        $fpagesize = 4;
        
        $this->view->bPushed = $this->_cart->getBookLiteList("pushed", $pagesize, $currpage,$total);
        $this->view->bTransported = $this->_cart->getBookLiteList("transported", $pagesize, $currpage,$total);
        
        $this->view->bfCart = $this->_cart->getBookLiteList("fcart", $pagesize, $currpage,$total);
        $this->view->bRS = $this->_cart->getBookLiteList("bRS", $pagesize, $currpage,$total);
        /*get all book in cart
        $this->_cbooks = $this->_cart->getBookLiteList();
  
        $this->view->pushedB = $this->_cbooks["pushed"];
        $this->view->transported = $this->_cbooks["transported"];
        $this->view->fcart = $this->_cbooks["fcart"];
         * 
         */

    }
    public function getpushed(){}


    public function viewcartAction()
    {
        $this->_helper->layout()->setLayout('layout_home_2');
        
        $mySession=new Zend_Session_Namespace();

        $numberBookInCart=0;
        $cartModel=new Personal_Model_MCart();
        $uid='';
        $cid='';
        if(isset ($mySession->uid) && isset($mySession->username))
        {
            $uid=$mySession->uid;
        }
        else if(isset($mySession->idcart))
        {
            $cid=$mySession->idcart;
        }
        else
        {
            $this->view->numberbook=$numberBookInCart;
            return;
        }
        $res=$cartModel->getBookInCart($uid,$cid);
        $numberBookInCart=count($res);
        $this->view->numberbook=$numberBookInCart;
        if($numberBookInCart>0)
        {
            $this->view->bookcart=$res;
        }
    }
}

